package com.hw.shortlink.project.controller;

import com.hw.shortlink.project.common.convention.response.Result;
import com.hw.shortlink.project.common.convention.response.Results;
import com.hw.shortlink.project.service.URLInfoService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequiredArgsConstructor
public class URLInfoController {

    private final URLInfoService urlInfoService;


    /**
     * 获取网站标题
     * @param url
     * @return
     */
    @GetMapping("/api/short-link/title")
    public Result<String> getTitleFromUrl(@RequestParam("url") String url){
        return Results.success(urlInfoService.getTitleByUrl(url));
    }


    /**
     * 获取网站图标
     * @param url
     * @return
     */
    @GetMapping("/api/short-link/favicon")
    public Result<String> getFaviconFromUrl(@RequestParam("url") String url){
        return Results.success(urlInfoService.getFavicon(url));
    }
}
